package com.fitbet.wechat.dao;

import java.util.List;
import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.fitbet.entity.bet.UserBet;
import com.fitbet.entity.bet.UserBetStatus;
import com.fitbet.entity.bet.UserBetSupport;
import com.fitbet.entity.bet.UserBetSupportStatus;

@Dao("hibernate")
public interface UserBetDao {
	
	/**
	 * 
	 * @param userId
	 * @return
	 */
	@Query("FROM UserBet WHERE user.id =:userId AND disabled = false AND status in (:status)")
	public List<UserBet> list(@Variable("userId") Long userId, @Variable("status") UserBetStatus[] status);
	
	@Limit
	@Query("FROM UserBet WHERE disabled = false AND status in (:status) ORDER BY thumbup DESC, thumbdown DESC")
	public List<UserBet> listHot(@Variable("status") UserBetStatus[] status, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);

	/**
	 * 
	 * @param userId
	 * @return
	 */
	@Query("FROM UserBetSupport WHERE user.id =:userId AND disabled = false AND status in (:status)")
	public List<UserBetSupport> listUserBetSupport(@Variable("userId") Long userId, @Variable("status") UserBetSupportStatus[] status);
	
	/**
	 * 
	 * @param userId
	 * @param betId
	 * @return
	 */
	@Query("FROM UserBet WHERE user.id =:userId AND disabled = false AND bet.id = :betId AND status in (:status)")
    public UserBet loadUserBet(@Variable("userId") Long userId, @Variable("betId") Long betId, @Variable("status") UserBetStatus[] status);
	
	/**
	 * 
	 * @param id
	 * @return
	 */
	@Query("FROM UserBet WHERE id =:id AND disabled = false AND status in (:status)")
    public UserBet loadUserBet(@Variable("id") Long id, @Variable("status") UserBetStatus[] status);
}
